<template>
  <div class="app-container app-containerMoney containerMoneynews app-containerMoneytabel">
    <el-col :offset="22" style="margin-bottom: 5px">
      <el-button plain @click="$router.back(-1)">返回</el-button>
    </el-col>
    <el-table :data="list" v-loading.body="listLoading" element-loading-text="Loading" fit highlight-current-row>
      <el-table-column >
        <template slot-scope="scope">
          <a @click="detail(scope.row.id)">
          {{scope.row.title}}
          </a>
        </template>
      </el-table-column>
      <el-table-column >
        <template slot-scope="scope">
          <i class="el-icon-time"></i>
          <span v-if="scope.row.createTime">{{scope.row.createTime | parseTime('{y}-{m}-{d} {h}:{i}')}}</span>
        </template>
      </el-table-column>
    </el-table>
    <div class="pagination-container">
      <el-pagination background @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="listQuery.page"
        :page-sizes="[10,20,30, 50]" :page-size="listQuery.size" layout="total, sizes, prev, pager, next, jumper"
        :total="total">
      </el-pagination>
    </div>
  </div>
</template>
<script>
import { queryPage } from "@/api/news";

export default {
  props: ['type'],
  data() {
    return {
      height: 500,
      content: "",
      list: null,
      total: 0,
      listLoading: true,
      username: "",
      listQuery: {
        page: 1,
        size: 10,
        type: this.type,
        sort: "+id"
      }
    };
  },
  mounted: function() {
    this.fetchData();
  },
  methods: {
    fetchData() {
      this.listLoading = true;
      queryPage(this.listQuery).then(response => {
        this.list = response.data.records;
        this.total = response.data.total;
        this.listLoading = false;
      });
      this.listLoading = false;
    },
    handleFilter() {
      this.listQuery.page = 1;
      this.fetchData();
    },
    handleSizeChange(val) {
      this.listQuery.size = val;
      this.fetchData();
    },
    handleCurrentChange(val) {
      this.listQuery.page = val;
      this.fetchData();
    },
    detail(id) {
      this.$router.push({
        path: "/news/newdetail",
        query: { id: id }
      });
    },
  }
};
</script>

<style scoped>
.dataForm_tinymce {
  height: 510px;
  width: 100%;
  overflow: hidden;
  padding: 3px;
}

.filter-container {
  margin-bottom: 20px;
  overflow: hidden;
}

.filter-container-option {
  display: flex;
  flex-wrap: nowrap;
  margin-bottom: 15px;
}

.pagination-container {
  margin-top: 25px;
  overflow: hidden;
  display: flex;
  justify-content: flex-end;
}

.app-containerMoney {
  margin-right: 20px;
}

.filter-itemBut {
  margin-left: 25px;
}
</style>